package cn.wizzer.app.user.modules.models;

import cn.wizzer.framework.base.model.BaseModel;
import lombok.Data;
import org.nutz.dao.entity.annotation.*;
import org.nutz.dao.interceptor.annotation.PrevInsert;
import org.nutz.json.JsonField;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 用户管理
 */
//Nutz暂不支持全文索引，暂时不加，当出现问题时再加
@Data
@Table("user")
@Comment("用户表")
@TableIndexes({@Index(name = "unique_userName", fields = {"userName"}, unique = true),
        @Index(name = "index_ctAt", fields = {"ctAt"}, unique = false),
        @Index(name = "unique_email", fields = {"email"}, unique = true),
        @Index(name = "unique_inviteCode", fields = {"inviteCode"}, unique = true)})
@TableMeta("{mysql-charset:'utf8mb4'}")
public class User extends BaseModel implements Serializable {

    @Column
    @Name
    @Comment("ID")
    @ColDefine(type = ColType.VARCHAR, width = 32)
//    @PrevInsert(uu32 = true)
    private String id;

    @Column
    @Comment("昵称")
    @ColDefine(type = ColType.VARCHAR, width = 20)
    private String nickName;

    /**
     * 规则邀请码前两位+随机生成八位数。钻石划转使用
     */
    @Column
    @Comment("用户名默认与昵称相同")
    @ColDefine(type = ColType.VARCHAR, width = 20)
    private String userName;

    @Column
    @Comment("邮箱")
    @ColDefine(type = ColType.VARCHAR, width = 64)
    private String email;

    @Column
    @Comment("手机号前缀")
    @ColDefine(type = ColType.VARCHAR, width = 8)
    private String phonePrefix;

    @Column
    @Comment("手机号")
    @ColDefine(type = ColType.VARCHAR, width = 16)
    private String phone;


    @Column
    @Comment("真实姓名")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String realName;

    @Column
    @Comment("身份证号码")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String idNo;

    @Column
    @Comment("关系路径path，最后一级为自己")
    @ColDefine(type = ColType.TEXT)
    private String path;

    @Column
    @Comment("层级，默认为第一层")
    @ColDefine(type = ColType.INT, width = 4)
    @Default("1")
    private Integer layer;

    @Column
    @Comment("签名")
    @JsonField
    @ColDefine(type = ColType.VARCHAR, width = 256)
    private String sign;

    @Column
    @Comment("密码")
    @ColDefine(type = ColType.VARCHAR, width = 256)
    private String password;

    @Column
    @Comment("交易密码")
    @ColDefine(type = ColType.VARCHAR, width = 256)
    private String transactionPwd;

    @Column
    @Comment("随机盐")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String salt;

    @Column
    @Comment("是否在线0否1是")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean isOnline;

    @Column
    @Comment("是否禁用0否1是")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean disabled;

    @Column
    @Comment("禁言0否1是")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean sessionDisabled;

    @Column
    @Comment("邀请码")
    @ColDefine(type = ColType.VARCHAR, width = 8)
    private String inviteCode;

    @Column
    @Comment("邀请人")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String inviter;

    /**
     * 是否为客服
     */
    @Column
    @Comment("客服")
    @Default("0")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean attendant;

    @Column
    @Comment("创建时间")
    @PrevInsert(els = @EL("$me.now()"))
    private Long ctAt;

    @Column
    @Comment("最后登录")
    private Long lastLoginAt;

    @Column
    @Comment("登录次数")
    @Default("0")
    private Long loginTimes;

    @Column
    @Comment("登录时长(h)")
    @ColDefine(type = ColType.FLOAT, width = 10, precision = 2)
    @Default("0")
    private BigDecimal loginDuration;

    @Column
    @Comment("登录ip")
    @ColDefine(type = ColType.VARCHAR, width = 255)
    private String ip;

    @Column
    @Comment("免费提现次数")
    @ColDefine(type = ColType.INT, width = 4, notNull = true)
    @Default("3")
    private Integer withdrawFreeTimes;


    @Column
    @Comment("游客账号")
    @Default("0")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean visitor;
    /**
     * 统计时候用的
     */
    @Column
    @Comment("内部账号")
    @Default("0")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean inside;
    /**
     * 提现流水倍数
     */
    @Column
    @Comment("提现流水倍数")
    @Default("1")
    @ColDefine(type = ColType.FLOAT, width = 10, precision = 2)
    private BigDecimal multiple;

    /**
     * 流水限制额度
     * 1、流水倍数，调整，默认1，充值多少，需要达到的流水
     * 2、以前的流水汇总，需要进行初始化
     */
    @Column
    @Comment("流水限制额度")
    @Default("0")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    private BigDecimal transRestriction = BigDecimal.ZERO;


    @Column
    @Comment("有效流水")
    @Default("0")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    private BigDecimal effectQuota = BigDecimal.ZERO;

    /**
     * 默认有一张头像，这张自己弄一个上传一下
     */
    @Column
    @Comment("头像")
    @ColDefine(type = ColType.VARCHAR, width = 128)
    private String headPicture = "/image/logo/defaultHeadPicture.png";


    @Column
    @Comment("备注")
    @ColDefine(type = ColType.VARCHAR, width = 128)
    private String remark;


    /**
     * 邀请用户数量
     */
    private Integer invitedNum;
}






